package com.dc.ftp.activity.loan;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dc.ftp.R;
import com.dc.ftp.base.SPBaseActivity;
import com.dc.ftp.view.RoundAngleImageView;

import java.io.File;

public class RealNameInfoActivity extends SPBaseActivity implements View.OnClickListener{

    private EditText etRealName;
    private EditText etIdCard;
    private TextView tvTakePhoto1;
    private TextView tvTakePhoto2;
    private TextView tvTakePhoto3;
    private RoundAngleImageView ivPhoto1;
    private RoundAngleImageView ivPhoto2;
    private RoundAngleImageView ivPhoto3;
    private TextView tvOk;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_real_name_info);
        super.init();
        setHeadTitle(true,"实名信息");

    }

    @Override
    public void initView() {
         etRealName = (EditText) findViewById(R.id.et_real_name);
         etIdCard = (EditText) findViewById(R.id.et_id_card);


        ivPhoto1 = (RoundAngleImageView) findViewById(R.id.iv_photo1);
        ivPhoto2 = (RoundAngleImageView) findViewById(R.id.iv_photo2);
        ivPhoto3 = (RoundAngleImageView) findViewById(R.id.iv_photo3);
        
         tvTakePhoto1 = (TextView) findViewById(R.id.take_photo1);
         tvTakePhoto2 = (TextView) findViewById(R.id.take_photo2);
         tvTakePhoto3 = (TextView) findViewById(R.id.take_photo3);
        tvTakePhoto1.setOnClickListener(this);
        tvTakePhoto2.setOnClickListener(this);
        tvTakePhoto3.setOnClickListener(this);

        tvOk = (TextView) findViewById(R.id.btn_ok);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {

    }



    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.take_photo1:
                Intent intent1 = new Intent(RealNameInfoActivity.this, MyTakingPhotoActivity.class);
                intent1.putExtra("tag","1");
                startActivityForResult(intent1,555);
                break;
            case R.id.take_photo2:
                Intent intent2 = new Intent(RealNameInfoActivity.this, MyTakingPhotoActivity.class);
                intent2.putExtra("tag","2");
                startActivityForResult(intent2,555);
                break;
            case R.id.take_photo3:
                Intent intent3 = new Intent(RealNameInfoActivity.this, MyTakingPhotoActivity.class);
                intent3.putExtra("tag","3");
                startActivityForResult(intent3,555);
                break;
            default:break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode== Activity.RESULT_CANCELED){
            return;
        }

        if (requestCode==555&&resultCode==556){
            String photoPath = data.getStringExtra("photoPath");
            String tag = data.getStringExtra("tag");
            //showAlert(res);
            if (!photoPath.equals("")){

                File file = new File(photoPath);
                if (file.exists()) {
                    Bitmap bm = BitmapFactory.decodeFile(photoPath);

                    if (tag.equals("1")){
                        ivPhoto1.setImageBitmap(bm);
                    }else if (tag.equals("2")){
                        ivPhoto2.setImageBitmap(bm);
                    }else if (tag.equals("3")){
                        ivPhoto3.setImageBitmap(bm);
                    }



                }
            }
        }
    }
}
